<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="学生姓名" prop="studentName">
        <el-input
          v-model="queryParams.studentName"
          placeholder="请输入学生姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="学生微信" prop="wechat">-->
<!--        <el-input-->
<!--          v-model="queryParams.wechat"-->
<!--          placeholder="请输入学生微信"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="学生手机号" prop="phone">-->
<!--        <el-input-->
<!--          v-model="queryParams.phone"-->
<!--          placeholder="请输入学生手机号"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="预订时间" prop="bookedTime">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.bookedTime"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择预订时间">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
      <el-form-item label="帮扶老师" prop="teacher">
        <el-input
          v-model="queryParams.teacher"
          placeholder="请输入帮扶老师"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="解决状态" prop="state">-->
<!--        <el-input-->
<!--          v-model="queryParams.state"-->
<!--          placeholder="请输入解决状态，0待处理，1已解决"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['employment:assist:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['employment:assist:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['employment:assist:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['employment:assist:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="assistList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="${comment}" align="center" prop="id" />-->
      <el-table-column label="学生姓名" align="center" prop="studentName" />
      <el-table-column label="学生微信" align="center" prop="wechat" />
      <el-table-column label="学生手机号" align="center" prop="phone" />
      <el-table-column label="预订时间" align="center" prop="bookedTime" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.bookedTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="问题类型" align="center" prop="problemType" />
      <el-table-column label="帮扶老师" align="center" prop="teacher" />
      <el-table-column label="备注" align="center" prop="note" />
      <el-table-column label="解决状态" align="center" prop="state" >
        <template scope="scope">
          <span v-if="scope.row.state==1" style="color: green">已完成</span>
          <span v-if="scope.row.state==0" style="color: blue">待帮扶</span>
          <span v-if="scope.row.state==2" style="color: black">已评价</span>
          <span v-if="scope.row.state==-1" style="color: red">已移交</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['employment:assist:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['employment:assist:remove']"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-over"
            @click="handOver(scope.row)"
          >移交</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-over"
            @click="handFinish(scope.row)"
          >完成</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改就业帮扶对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="学生姓名" prop="studentName">
          <el-input v-model="form.studentName" placeholder="请输入学生姓名" />
        </el-form-item>
        <el-form-item label="学生微信" prop="wechat">
          <el-input v-model="form.wechat" placeholder="请输入学生微信" />
        </el-form-item>
        <el-form-item label="学生手机号" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入学生手机号" />
        </el-form-item>
        <el-form-item label="预订时间" prop="bookedTime">
          <el-date-picker clearable
            v-model="form.bookedTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择预订时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="帮扶老师" prop="teacher">
          <el-input v-model="form.teacher" placeholder="请输入帮扶老师" />
        </el-form-item>
        <el-form-item label="备注" prop="note">
          <el-input v-model="form.note" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="解决状态" prop="state">
          <el-input v-model="form.state" placeholder="请输入解决状态，0待处理，1已解决" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <!-- 帮扶移交 -->
    <el-dialog :title="title" :visible.sync="opens" width="500px" append-to-body>
      <el-form ref="overForm" :model="overForm" :rules="rules" label-width="80px">
<!--        <el-form-item label="帮扶任务id" prop="assistId">-->
<!--        </el-form-item>-->
        <el-form-item label="咨询老师" prop="teacher">
          <el-select v-model="overForm.teacher" placeholder="请选择咨询老师" clearable :style="{width: '100%'}">
            <el-option v-for="(item, index) in teacherOptions" :key="index" :label="item.name"
                       :value="item.name" :disabled="item.disabled"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="问题描述" prop="note">
          <el-input v-model="overForm.note" type="textarea" placeholder="请输入问题描述"
                    :autosize="{minRows: 4, maxRows: 4}" :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="发送邮件" prop="send">
          <el-switch v-model="overForm.send" :active-value='1' :inactive-value='0'></el-switch>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormData">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <el-dialog :title="title" :visible.sync="finishOpen" width="500px" append-to-body>
      <el-form ref="finishForm" :model="finishForm" :rules="rules" label-width="80px">
        <el-form-item label="确定完成帮扶任务" prop="send">
<!--          <el-switch v-model="overForm.send" :active-value='1' :inactive-value='0'></el-switch>-->
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFinishForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>




</template>

<script>
import { listAssist, getAssist, delAssist, addAssist, updateAssist, handOver,  handFinish} from "@/api/employment/assist";
import {listTeacher} from "@/api/help/help";

export default {
  name: "Assist",
  data() {
    return {
      finishForm:[],
      teacherOptions: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 就业帮扶表格数据
      assistList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      opens: false,
      finishOpen : false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        studentName: null,
        wechat: null,
        phone: null,
        bookedTime: null,
        problemType: null,
        teacher: null,
        note: null,
        state: null
      },
      // 表单参数
      form: {},
      overForm: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();

  },
  methods: {
    getTeacherOptions() {
      listTeacher().then(res => {
        this.teacherOptions = res.rows
      })
    },
    /** 查询就业帮扶列表 */
    getList() {
      this.loading = true;
      listAssist(this.queryParams).then(response => {
        this.assistList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.opens = false;
      this.finishOpen = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        studentName: null,
        wechat: null,
        phone: null,
        bookedTime: null,
        problemType: null,
        teacher: null,
        note: null,
        state: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加就业帮扶";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getAssist(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改就业帮扶";
      });
    },
    /** 完成帮扶任务提交 */
    submitFinishForm() {
      this.$refs["finishForm"].validate(valid => {
        console.log(this.finishForm.id)
        handFinish(this.finishForm.id).then(res => {
          this.$modal.msgSuccess("帮扶完成");
          this.finishOpen = false;
          this.getList();
        })
      })
    },
    /** 帮扶移交提交 */
    submitFormData(row) {

      this.$refs["overForm"].validate(valid => {
        handOver(this.overForm).then(res => {
          this.$modal.msgSuccess("移交成功");
          this.opens = false;
        })
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAssist(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAssist(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 完成帮扶任务按钮 */
    handFinish(row) {
      this.finishForm.id = row.id
      this.finishOpen = true;
      this.getList();
    },
    /** 移交按钮操作*/
    handOver(row) {
      this.getTeacherOptions();
      console.log(row)
      this.overForm.assistId = row.id;
      // handOver(id).then(res => {
      //   this.$modal.msgSuccess("新增成功");
      // })
      this.opens = true;

    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除就业帮扶编号为"' + ids + '"的数据项？').then(function() {
        return delAssist(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('employment/assist/export', {
        ...this.queryParams
      }, `assist_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>



<!--<template>-->
<!--  <div>-->
<!--    <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="100px">-->
<!--      <el-form-item label="发送邮件" prop="send">-->
<!--        <el-switch v-model="formData.send" :active-value='1' :inactive-value='0'></el-switch>-->
<!--      </el-form-item>-->
<!--      <el-form-item size="large">-->
<!--        <el-button type="primary" @click="submitForm">提交</el-button>-->
<!--        <el-button @click="resetForm">重置</el-button>-->
<!--      </el-form-item>-->
<!--    </el-form>-->
<!--  </div>-->
<!--</template>-->
<!--<script>-->
<!--export default {-->
<!--  components: {},-->
<!--  props: [],-->
<!--  data() {-->
<!--    return {-->
<!--      formData: {-->
<!--        send: false,-->
<!--      },-->
<!--      rules: {},-->
<!--    }-->
<!--  },-->
<!--  computed: {},-->
<!--  watch: {},-->
<!--  created() {},-->
<!--  mounted() {},-->
<!--  methods: {-->
<!--    submitForm() {-->
<!--      this.$refs['elForm'].validate(valid => {-->
<!--        if (!valid) return-->
<!--        // TODO 提交表单-->
<!--      })-->
<!--    },-->
<!--    resetForm() {-->
<!--      this.$refs['elForm'].resetFields()-->
<!--    },-->
<!--  }-->
<!--}-->

<!--</script>-->
<!--<style>-->
<!--</style>-->


